package com.woniuxy.util;

import com.woniuxy.node.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class TreeNodeutil {
    
    public static List<TreeNode> bluid(List<TreeNode> treeNodes,int topId){
        List<TreeNode> treeNodesList = new ArrayList<>();
        for (TreeNode treeNode : treeNodes) {
      if (treeNode.getPid()==topId){
            treeNodesList.add(treeNode);
      }
            for (TreeNode node : treeNodes) {
                if (node.getPid()==treeNode.getId()){
                    treeNode.getChilren().add(node);
                }
            }
        }
        return treeNodesList;
    }

}
